package com.lanou.dllo.soccernews.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.lanou.dllo.soccernews.R;
import com.lanou.dllo.soccernews.bean.CircleShowBean;
import com.lanou.dllo.soccernews.volley.GetVolleyDatasUtil;
import com.lanou.dllo.soccernews.volley.VolleySingleton;

import java.util.List;

/**
 * Created by dllo on 15/10/30.
 */
public class CircleGridViewAdapter extends BaseAdapter {

    private List<CircleShowBean.GroupsEntity> groupsEntityList;

    private Context context;
    private LayoutInflater mLayoutInflater;

    //    public void addData(List<CircleShowBean.GroupsEntity> groupsEntityList)
//    {
//        this.groupsEntityList = groupsEntityList;
//        notifyDataSetChanged();
//    }
    public CircleGridViewAdapter(Context context, List<CircleShowBean.GroupsEntity> groupsEntityList) {
        this.context = context;
        this.groupsEntityList = groupsEntityList;
        mLayoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return groupsEntityList.size();
    }

    @Override
    public Object getItem(int position) {
        return groupsEntityList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ExpandableGridVIewHodle hodle;
        if (convertView == null) {
            hodle = new ExpandableGridVIewHodle();
            convertView = mLayoutInflater.inflate(R.layout.item_expandablegrid, null);
            hodle.thumb = (ImageView) convertView.findViewById(R.id.cii_thumb);
            hodle.join_user_total = (TextView) convertView.findViewById(R.id.cii_join_user_total);
            hodle.topic_total = (TextView) convertView.findViewById(R.id.cii_topic_total);
            hodle.title = (TextView) convertView.findViewById(R.id.cii_title);
            convertView.setTag(hodle);


        } else {
            hodle = (ExpandableGridVIewHodle) convertView.getTag();

        }
        // List<CircleShowBean.GroupsEntity> groups = getGroup(groupPosition).getGroups();
        CircleShowBean.GroupsEntity group = groupsEntityList.get(position);


        if (groupsEntityList != null) {
            hodle.title.setText(group.getTitle());
            Log.i("lanou", group.getTitle() + "反反复复反反复复");
            hodle.topic_total.setText("帖子 " + group.getTopic_total());
            hodle.join_user_total.setText("关注 "+group.getJoin_user_total());
            String url = group.getThumb();

          //  GetVolleyDatasUtil.getBitmapRequest(url, hodle.thumb);
           GetVolleyDatasUtil.getNetWorkImg(url,hodle.thumb);
        }


        return convertView;
    }

    class ExpandableGridVIewHodle {
        private ImageView thumb;
        private TextView title, join_user_total, topic_total;
    }
}
